package com.yusys.pattern.mode.single;

/**
 * 懒汉模式 双重检查锁定单例模式
 */
public class SafeSingle3 {
    public volatile  static SafeSingle3 instance;

    public static SafeSingle3 getInstance(){
        //如果instance不用volatile修饰，instance不为null时可能由于是指令重排序，对象实际上没有创建完，导致线程不安全
        if (instance == null){
            synchronized (SafeSingle3.class){//类锁
                if(instance == null){
                    instance = new SafeSingle3();
                }

            }
        }
        return instance;
    }
}
